package com.aipp.mall.h5.controller;

import com.aipp.mall.common.anno.Note;
import com.aipp.mall.common.model.Query;
import com.aipp.mall.h5.domain.entity.MemberCoupon;
import com.aipp.mall.h5.domain.query.MemberCouponQuery;
import com.aipp.mall.h5.domain.vo.CouponActivityVO;
import com.aipp.mall.h5.service.CouponActivityService;
import com.aipp.mall.h5.service.MemberCouponService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Administrator
 */
@Note("优惠券接口列表")
@RestController
@RequestMapping("/h5/coupon")
public class H5CouponController {

    @Autowired
    private CouponActivityService couponActivityService;

    @Autowired
    private MemberCouponService memberCouponService;

    @PostMapping("/activity/list")
    public ResponseEntity<IPage<CouponActivityVO>> list(Query query) {
        //获取所有未过期且运行中的活动
        return ResponseEntity.ok(couponActivityService.selectListByH5(query));
    }

    @GetMapping("/activity/get")
    public ResponseEntity<CouponActivityVO> getDetail(Long id) {
        CouponActivityVO detail = couponActivityService.getDetail(id);
        return ResponseEntity.ok(detail);
    }

    @PostMapping("/receive")
    public ResponseEntity<Boolean> receiveCoupon(Long id) {
        return ResponseEntity.ok(couponActivityService.receiveCoupon(id));
    }

    @PostMapping("/list")
    public ResponseEntity<IPage<MemberCoupon>> list(@RequestBody MemberCouponQuery query) {
        //获取所有未过期且运行中的活动
        return ResponseEntity.ok(memberCouponService.selectListByH5(query));
    }

    /**
     * 根据购买的商品筛选可用优惠券
     *
     * @param query
     * @return
     */
    @PostMapping("/can/use/list")
    public ResponseEntity<List<MemberCoupon>> getCanUseList(@RequestBody MemberCouponQuery query) {
        return ResponseEntity.ok(memberCouponService.getCanUseList(query.getProducts()));
    }

}
